package com.ihelp.rest.mis.platform.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ihelp.rest.mis.platform.dao.AbnormaltitleDao;
import com.ihelp.rest.mis.pojo.Abnormaltitle;
import com.ihelp.rest.utils.JsonCommon;

@Service
public class AbnormaltitleService {
	@Autowired
	private AbnormaltitleDao AbnormaltitleDao;
	
	/**
	 * 查询异常上网时间返回JSON串
	 * @param queryCondition
	 * @param start
	 * @param pageSize
	 * @param sort
	 * @param order
	 * @return
	 */
	public String findAbnormaltitlePage(Abnormaltitle queryCondition,int start,int pageSize,String sort, String order){
		return JsonCommon.getGridJson(this.AbnormaltitleDao.queryAbnormaltitlePage(queryCondition,start,pageSize,sort,order)).toString();
	}
	
	public Abnormaltitle getAbnormaltitleById(String id){
		return this.AbnormaltitleDao.get(id);
	}
	
	/**
	 * 保存异常上网时间
	 * @param Abnormaltitle
	 * @return
	 */
	public String saveAbnormaltitle(Abnormaltitle Abnormaltitle){
		Map<String ,Object> result = new HashMap<String, Object>();
		result.put("success", false);
		SimpleDateFormat  sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String addtime = sdf.format(new Date());
		try{
			if(StringUtils.isBlank(Abnormaltitle.getId())){
				Abnormaltitle.setId(null);
				Abnormaltitle.setAddtime(addtime);
			}else{
				Abnormaltitle.setAddtime(addtime);
			}
			this.AbnormaltitleDao.saveOrUpdate(Abnormaltitle);
			result.put("success", true);
			result.put("data", "保存成功");
		}catch(Exception e){
			result.put("data", "保存失败"+e.getMessage());
		}
		return JSONObject.fromObject(result).toString() ;
	}
	
	
	/**
	 * 删除异常上网时间
	 * @param ids
	 * @return
	 */
	public String delAbnormaltitle(String ids){
		Map<String ,Object> result = new HashMap<String, Object>();
		result.put("success", false);
		try{
			this.AbnormaltitleDao.dropAbnormaltitle(ids);
			result.put("success", true);
			result.put("data", "删除成功");
		}catch(Exception e){
			result.put("data", "删除失败"+e.getMessage());
		}
		return JSONObject.fromObject(result).toString() ;
	}
}
